<!-- 订单状态 -->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>订单</title>
    <link rel="icon" href="__ROOT__/public/lcbook.ico" type="image/x-icon">
    <link rel="stylesheet" href="__ROOT__/public/static/css/common.css">
    <link rel="stylesheet" href="__ROOT__/public/static/css/header.css">
    <link rel="stylesheet" href="__ROOT__/public/static/css/popBox.css">
    <link rel="stylesheet" href="__ROOT__/public/static/css/order.css">
    <link rel="stylesheet" href="__ROOT__/public/static/css/emptyMsg.css">


    <!-- fontawesome字体 -->
    <link rel="stylesheet" href="__ROOT__/public/static/font/font-awesome.min.css">
</head>

<body>
    <!-- 头部 -->
    {include file="./public/common/header.html"/}

    <div id="order">
        <!-- 筛选条件 -->
        <div class="orderSearch">
            <div class="orderSearchItem">
                <label for="">开始：</label>
                <input name="starttime" type="date" class="datePicker" value="{$Think.session.starttime}">
            </div>
            <div class="orderSearchItem">
                <label for="">结束：</label>
                <input name="endtime" type="date" class="datePicker" value="{$Think.session.endtime}">
            </div>
            <div class="orderSearchItem">
                <label for="">总金额不低于：</label>
                <input name="lowprice" type="number" min="0" max="9999" value="{$Think.session.lowprice}">
            </div>

            <div class="orderSearchItem">
                <label for="">订单类型：</label>
                <select name="ordertype" id="">
                    <option value="不限">不限</option>
                    <option value="未付款">未付款</option>
                    <option value="未发货">未发货</option>
                    <option value="已发货">已发货</option>
                    <option value="未评价">未评价</option>
                    <option value="已完成">已完成</option>
                </select>
            </div>

            <div class="orderSearchItem">
                <input name="keyword" type="text" placeholder="书籍关键字" value="{$Think.session.keyword}">
            </div>
            <button class="orderSearchBtn">&#xf002</button>
        </div>

        <!-- 订单内容 -->
        <div class="orderContent">
            {assign name="count" value="0" /}
            {foreach $showorder as $order}
            {assign name="count" value="$count+1" /}
            <!-- 一个订单 -->
            <div class="orderBox">
                <div class="row">
                    <p>
                        <span>订单编号：</span>
                        <span>{$order.orderID}</span>
                    </p>
                    <p>
                        <span>下单时间：</span>
                        <span>{$order.inputtime}</span>
                    </p>
                    <p><a class="del" href="javascript:void(0)" data-id="{$order.orderID}">
                            <i class="fa fa-trash-o" aria-hidden="true"></i></a></p>
                </div>
                <div class="row">
                    <p>
                        <span>总金额：</span>
                        <span class="activate_font">{$order.shifu}</span>
                    </p>
                    <p>
                        <span>支付方式：</span>
                        <span>微信支付</span>
                    </p>
                </div>
                <div class="row">
                    <p>
                        <span>收货人：</span>
                        <span>{$order.sname}</span>
                    </p>
                </div>
                <div class="row address">
                    <p>
                        <span>收货地址：</span>
                        <span>{$order.address}</span>
                    </p>
                </div>

                <!-- 未付款、未发货、已发货、未评价、已完成 -->

                <div class="row">
                    <p>
                        <span>订单状态：</span>
                        <span>{$order.status}</span>
                        {switch name="$order.status"}
                        {case value="未付款"}
                        <a href="{:url('order/pay')}?orderID={$order.orderID}"><span class="activate_font ml12">去付款</span></a>
                        {/case}

                        {case value="已发货"}
                        <a href="{:url('order/orderUpdate')}?orderID={$order.orderID}"><span class="activate_font ml12">确认收货</span></a>
                        {/case}

                        {case value="未评价"}
                        <a href="{:url('order/evaluate')}?orderID={$order.orderID}"><span class="activate_font ml12">去评价</span></a>
                        {/case}
                        {/switch}
                    </p>
                </div>
                {foreach $orderlists as $orderlist}
                {foreach $orderlist as $shoplist}
                {if($order.orderID eq $shoplist.orderID)}
                <div class="orderShop">
                    <ul class="orderShopBox">
                        <a href="{:url('shopdetail/shopdetail')}?bookID={$shoplist.bookID}">
                            <li class="jcstart f333"><img src="__ROOT__/public/static/image/{$shoplist.pictures}"
                                    alt="">
                                <span class="mt12">{$shoplist.bname}</span></li>
                        </a>
                        <li class="mt12">￥{$shoplist.yourprice}</li>
                        <li class="mt12">×{$shoplist.num}</li>
                        <li class="f333 mt12">￥{$shoplist.num * $shoplist.yourprice}</li>
                    </ul>
                </div>
                {/if}
                {/foreach}
                {/foreach}
            </div>
            {/foreach}
        </div>

        {if condition="$count == 0 "}
        <!-- 无订单时显示 -->
        <div id="empty" style="display: block;" align="center">
            <img src="__ROOT__/public/static/image/empty.png" alt="">
            <div>
                <h4 class="tit">没有订单哦！</h4>
                <p class="msg"><a href="{:url('index/index')}" class="activate_font">去随便逛逛吧，</a>看有没有喜欢的</p>
            </div>
        </div>
        {/if}

        <!-- 页码 -->
        <div class="page">{$page}</div>
    </div>

    <!-- js代码 -->
    <script src="__ROOT__/public/static/js/jquery-1.8.3.min.js"></script>
    <script src="__ROOT__/public/static/js/header.js"></script>
    <script>
        $(function () {
            init();

            //删除订单
            $(".del").click(function () {
                if (!confirm("你确定要删除吗？")) {
                    return;
                }
                var orderID = $(this).data("id");
                // alert(orderID);
                $(".del").parents("div").hide();
                $.post("{:url('order/delete')}", { 'orderID': orderID }, function (result) {
                    // alert(result);
                    if (result == "success") {
                        //$(".del").parents("div").hide();
                        window.location.href = "{:url('order/order')}";
                    }

                });
            });

            //搜素按钮
            $('.orderSearchBtn').click(function () {
                let starttime = $('input[name="starttime"]').val();
                let endtime = $('input[name="endtime"]').val();
                let lowprice = $('input[name="lowprice"]').val();
                let ordertype = $('select[name="ordertype"] option:selected').val();
                let keyword = $('input[name="keyword"]').val();

                window.location.href = `__ROOT__/index/order/order?starttime=${starttime}&endtime=${endtime}&lowprice=${lowprice}&ordertype=${ordertype}&keyword=${keyword}`;

                /* $.get("{:url('order/order')}", {
                    starttime: starttime,
                    endtime: endtime,
                    lowprice: lowprice,
                    ordertype: ordertype,
                    keyword: keyword
                },function(res){

                }); */
            });

        });

        function init() {
            //订单类型不为空
            if ('{$Think.session.ordertype}') {
                $('select[name="ordertype"] option').each(function () {
                    if ($(this).val() == '{$Think.session.ordertype}') {
                        $(this).prop("selected", true);
                    } else {
                        $(this).prop("selected", false);

                    }
                })
            }

            //时间判断
            // 初始化date为当前日期
            var time = new Date();
            var day = ("0" + time.getDate()).slice(-2);
            var month = ("0" + (time.getMonth() + 1)).slice(-2);
            var today = time.getFullYear() + "-" + (month) + "-" + (day);

            if (!'{$Think.session.starttime}') {
                $('input[name="starttime"]').val(today);
            }
            if (!'{$Think.session.endtime}') {
                day = ("0" + (time.getDate() + 1)).slice(-2);
                today = time.getFullYear() + "-" + (month) + "-" + (day);
                $('input[name="endtime"]').val(today);
            }
        }

    </script>
</body>

</html>